//
//  KWTAlarmFaultOptionVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/1/3.
//

#import "RHAlarmFaultOptionVC.h"
#import "RHAlarmFaultListVC.h"

@interface RHAlarmFaultOptionVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) NSArray *titleArr;

@end

@implementation RHAlarmFaultOptionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CFTabViewBgColor;
    self.navigationItem.title = @"消息".rh_localized;
    [self setupUI];
}

-(void)setupUI
{
    self.titleArr = @[@"设备告警信息".rh_localized,@"设备故障信息".rh_localized,@"设备保护信息".rh_localized];
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setSeparatorColor:UIColor.clearColor];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    _tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];

    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *iconArr = @[@"kwt_device_alarm_02",@"kwt_device_fault_02",@"kwt_device_protect_02"];
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.borderColor = kBorderColor.CGColor;
    bgView.layer.borderWidth = 1;
    bgView.layer.masksToBounds = YES;
    [cell.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(3, 15, 3, 15));
    }];
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:iconArr[indexPath.row]]];
    icon.contentMode = UIViewContentModeScaleAspectFit;
    [bgView addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.width.height.offset(32);
        make.centerY.mas_offset(0);
    }];
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = self.titleArr[indexPath.row];
    titleLab.font = kSYSTEMFONT(15);
    titleLab.textColor = kCOLOR_HEX(@"3F4443");
    titleLab.numberOfLines= 2;
    [bgView addSubview:titleLab];
    

    UIImageView *accesory = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
    accesory.contentMode = UIViewContentModeScaleAspectFit;
    [bgView addSubview:accesory];
    [accesory mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(15);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(icon.mas_right).offset(10);
        make.right.equalTo(accesory.mas_left).offset(-5);
        make.centerY.equalTo(icon);
    }];
    
    cell.contentView.backgroundColor = CFTabViewBgColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RHAlarmFaultListVC *listVC = [[RHAlarmFaultListVC alloc]initWithLevel:indexPath.row+1 deviceId:@""];
    listVC.showSeacrhView = YES;
    if(indexPath.row == 0){
        listVC.title = @"告警".rh_localized;
    }else if(indexPath.row == 1){
        listVC.title = @"故障".rh_localized;
    }else if(indexPath.row == 2){
        listVC.title = @"保护".rh_localized;
    }
    [self.navigationController pushViewController:listVC animated:YES];
}
@end
